package com.lpy.book.utils;

import com.lpy.book.model.User;

import javax.servlet.http.HttpSession;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ToolUtil {
    // 判断字符串是否为空
    public static boolean isEmpty(String str) {
          if(str != null && !"".equals(str)){
                 return false;
          }
           return true;

    }

    // 获取当前时间
    public static Long getTime() {
        return System.currentTimeMillis();
    }

    // 对时间进行格式化
    public static String getDateByTime(Long time) {
        SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
        String string = format.format(new Date(time));
        return string;
    }

    // 获取当前登录用户
    public static User getUser(HttpSession session){
          User user = (User) session.getAttribute("user");
          return user;
    }

    public static void setUser(HttpSession session,User user){
        session.setAttribute("user", user);
    }

    // 获取屏幕宽度与高度
    public static int getScreenWidth() {
        return Toolkit.getDefaultToolkit().getScreenSize().width;
    }

    public static int getScreenHeight() {
        return Toolkit.getDefaultToolkit().getScreenSize().height;
    }


}
